<template>
  <div v-if="isLocked" class="full-screen-lock">
    <div class="lock-content">
      <div>
        <el-input v-model="inputPassword" type="password" placeholder="请输入直播观看密码" />
      </div>
      <el-button type="primary" @click="unlock" style="margin-top: 20px">解锁</el-button>
    </div>
  </div>
</template>

<script setup>
const { proxy } = getCurrentInstance();

const props = defineProps({
    isLocked: {
        type: Boolean,
        default: false,
    },
    correctPassword: {
        type: String,
        default: ",",
    }
});

const inputPassword = ref('');
const emit = defineEmits();

const unlock = () => {
    if (inputPassword.value === props.correctPassword) {
        emit('unlocked'); // 发出解锁成功的事件
    } else {
        // alert("密码错误！");
        // console.error("密码错误！");
        // proxy.$modal.msgError("密码错误！");
        proxy.$modal.msgError("密码错误！");
        inputPassword.value = ''; // 清空输入框
    }
};
</script>

<style scoped>
.full-screen-lock {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.lock-content {
  text-align: center;
  background: white;
  padding: 20px;
  border-radius: 5px;
}

.lock-content h1 {
  margin-bottom: 20px;
}

.lock-content input {
  margin-bottom: 10px;
  padding: 10px;
  font-size: 16px;
}

.lock-content button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
</style>
